﻿// See https://aka.ms/new-console-template for more information
using AutoEntities;
using AutoMap;
using System.Diagnostics;

Console.WriteLine("Hello, World!");
// 映射速度：表达式 >= 纯实例对象映射 > 反射 > 序列化
Stopwatch stopwatch = new Stopwatch();
var people = new People
{
    Id = 1,
    Name = $"Name{1}",
    Age = 1,
    Address = $"Address{1}",
    Phone = $"Phone{1}",
    Email = $"Email{1}",
    Remark = $"Remark{1}",
    CreateDateTime = DateTime.Now,
    CreatorId = 1
};
// 开始计时
stopwatch.Start();
List<PeopleInfo> list = new();
for (int i = 0; i < 1000000; i++)
{
    var peopleinfo = EntityMapper.Map(people);
    list.Add(peopleinfo);
}
// 停止计时
stopwatch.Stop();

// 输出结果
Console.WriteLine($"直接创建实例代码执行时间: {stopwatch.ElapsedMilliseconds} 毫秒");
list.Clear();

Stopwatch stopwatch1 = new Stopwatch();
stopwatch1.Start();
for (int i = 0; i < 1000000; i++)
{
    var peopleinfo = ReflectorMapper.Map<People, PeopleInfo>(people);
    list.Add(peopleinfo);
}
stopwatch1.Stop();
Console.WriteLine($"通过反射创建实例代码执行时间: {stopwatch1.ElapsedMilliseconds} 毫秒");
list.Clear();

Stopwatch stopwatch2 = new Stopwatch();
stopwatch2.Start();
for (int i = 0; i < 1000000; i++)
{
    var peopleinfo = SerializeMapper.Map<People, PeopleInfo>(people);
    if (peopleinfo != null)
    {
        list.Add(peopleinfo);
    }
}
stopwatch2.Stop();
Console.WriteLine($"通过序列化创建实例代码执行时间: {stopwatch2.ElapsedMilliseconds} 毫秒");
list.Clear();

Stopwatch stopwatch3 = new Stopwatch();
stopwatch3.Start();
for (int i = 0; i < 1000000; i++)
{
    var peopleinfo = ExpressionMapper<People, PeopleInfo>.Map(people);
    if (peopleinfo != null)
    {
        list.Add(peopleinfo);
    }
}
stopwatch3.Stop();
Console.WriteLine($"通过序列化创建实例代码执行时间: {stopwatch3.ElapsedMilliseconds} 毫秒");